package com.loongtech.bi.manager.pay;

import com.loongtech.bi.entity.pay.EntityNotIdfaTotalCash;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NotIdfaTotalCashManager extends ManagerQueryCacheBase<EntityNotIdfaTotalCash> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 根据开始结束时间，求付费金额
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityNotIdfaTotalCash> getTotalCashByDate(Date dateStart, Date dateEnd) {
		return findByQuery("from EntityNotIdfaTotalCash  where 1=1 and day>=:dayStart and day<=:dayEnd order by day", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据开始结束时间，求付费金额对象
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityNotIdfaTotalCash> getAllTotalCashByAllKind(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("from EntityNotIdfaTotalCash where 1=1 and day>=:dayStart and day<=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+" ' and total_cash is not null", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据开始结束时间，求付费金额
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getTotalCashByAllKind(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select date_format(day,'%Y-%m-%d'),total_cash from EntityNotIdfaTotalCash where 1=1 and day>=:dayStart and day<=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+" ' and total_cash is not null", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据开始结束时间，求付费金额
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getSumTotalCashByAllKind(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select sum(total_cash)  from EntityNotIdfaTotalCash where 1=1 and day>=:dayStart and day<=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+" ' and total_cash is not null", "dayStart", dateStart, "dayEnd", dateEnd);
	}
}
